{% extends 'base.html' %}
{% block content %}
<div class="container mt-4">
    <h2>{% if object %}编辑传感器{% else %}添加传感器{% endif %}</h2>
    <form method="post">
        {% csrf_token %}
        <div class="form-group">
            {{ form.name.label_tag }}
            {{ form.name }}
        </div>
        <div class="form-group">
            {{ form.design_code.label_tag }}
            {{ form.design_code }}
        </div>
        <div class="form-group">
            {{ form.location.label_tag }}
            {{ form.location }}
        </div>
        <div class="form-group">
            {{ form.sensor_type.label_tag }}
            <select name="sensor_type" class="form-control" id="id_sensor_type">
                <option value="水位计" {% if form.sensor_type.value == '水位计' %}selected{% endif %}>水位计</option>
                <option value="渗压计" {% if form.sensor_type.value == '渗压计' %}selected{% endif %}>渗压计</option>
                <option value="测缝计" {% if form.sensor_type.value == '测缝计' %}selected{% endif %}>测缝计</option>
                <option value="裂缝计" {% if form.sensor_type.value == '裂缝计' %}selected{% endif %}>裂缝计</option>
            </select>
            <small class="form-text text-muted">传感器类型: 水位计, 渗压计, 测缝计, 裂缝计</small>
        </div>
        <div class="form-group">
            {{ form.alarm_threshold.label_tag }}
            <input type="number" step="0.01" name="alarm_threshold" class="form-control" id="id_alarm_threshold" value="{{ form.alarm_threshold.value }}">
            <small class="form-text text-muted">请输入数值型告警阈值</small>
        </div>
        <div class="form-group">
            {{ form.management_unit.label_tag }}
            {{ form.management_unit }}
        </div>
        <div class="form-group">
            {{ form.gateway.label_tag }}
            {{ form.gateway }}
        </div>
        <div class="form-group">
            {{ form.port_number.label_tag }}
            {{ form.port_number }}
        </div>
        <div class="form-group">
            {{ form.notes.label_tag }}
            {{ form.notes }}
        </div>
        <button type="submit" class="btn btn-primary">保存</button>
        <a href="{% url 'sensor-list' %}" class="btn btn-secondary">取消</a>
    </form>
</div>
{% endblock %}